package com.biscuit.page.basicservice.persistence.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.biscuit.page.basicservice.model.entities.mysql.SysSearchLog;
import com.biscuit.page.basicservice.persistence.mapper.SearchLogMapper;
import com.biscuit.page.basicservice.utils.WrapperUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author biscuit
 * @createTime 2024/6/4 10:03
 */
@Component
public class SearchLogDao extends ServiceImpl<SearchLogMapper, SysSearchLog> {

    public void insertAndIncrement(SysSearchLog sysSearchLog) {
        baseMapper.insertAndIncrement(sysSearchLog);
    }

    public void updateLog(Long id, String keyword) {
        LambdaUpdateWrapper<SysSearchLog> updateWrapper = WrapperUtil.instanceUpdate(SysSearchLog.class)
                .set(SysSearchLog::getIsGo, 1)
                .set(SysSearchLog::getUseSuggest, keyword)
                .eq(SysSearchLog::getId, id);
        super.update(updateWrapper);
    }
}
